package net.blank.world.world2D.business.unit
{
	import net.blank.commonInterface.IClone;
	import net.blank.commonInterface.IDestructible;
	import net.blank.commonInterface.IRecyclable;
	import net.blank.functionUtl.FunctionBinder;
	import net.blank.world.aStar.IUnit;
	import net.blank.world.world2D.template.unit.AbstractUnitTemplate;

	/**
	 * 单位抽象类
	 * @author blank
	 * 
	 */
	public class AbstractUnit implements IUnit, IDestructible, IRecyclable, IClone
	{
		/**
		 * 已经被摧毁
		 */
		private var _destroyed:Boolean=false;
		
		public function get destroyed():Boolean{
			return _destroyed;
		}
		
		public function destroy():void{
			_template=null;
			FunctionBinder.clearBindingFuns(setWorld_x,setWorld_y,setIsPassable,setPassCost);
			
			_destroyed=true;
		}
		
		/**
		 * 模板
		 */
		private var _template:AbstractUnitTemplate;
		
		/**
		 * <font color=#0000ff>[可绑定]</font>模板
		 * @param value
		 * 
		 */
		public function setTemplate(value:AbstractUnitTemplate):void{
			if(value != _template){
				_template=value;
				
				FunctionBinder.execCallbackFun(setTemplate,[this]);
			}
		}
		
		/**
		 * 模板
		 * @return 
		 * 
		 */
		public function getTemplate():AbstractUnitTemplate{
			return _template;
		}
		
		/**
		 * 世界坐标_x
		 */
		private var _world_x:int=-1;
		
		public function setWorld_x(value:int):void{
			if(value != _world_x){
				_world_x=value;
				
				FunctionBinder.execCallbackFun(setWorld_x,[this]);
			}
		}
		public function getWorld_x():int{
			return _world_x;
		}
		
		/**
		 * 世界坐标_y
		 */
		private var _world_y:int=-1;
		
		public function setWorld_y(value:int):void{
			if(value != _world_y){
				_world_y=value;
				
				FunctionBinder.execCallbackFun(setWorld_y,[this]);
			}
		}
		public function getWorld_y():int{
			return _world_y;
		}
		
		/**
		 * 是否可被穿越
		 */
		private var _isPassable:Boolean;
		
		public function setIsPassable(value:Boolean):void{
			if(value != _isPassable){
				_isPassable=value;
				
				FunctionBinder.execCallbackFun(setIsPassable,[this]);
			}
		}
		public function getIsPassable():Boolean{
			return _isPassable;
		}
		
		/**
		 * 穿越代价
		 */
		private var _passCost:int;
		
		public function setPassCost(value:int):void{
			if(value != _passCost){
				_passCost=value;
				
				FunctionBinder.execCallbackFun(setPassCost,[this]);
			}
		}
		
		public function getPassCost():int{
			return _passCost;
		}
		
		/**
		 * 单位抽象类
		 * @param template 模板
		 * 
		 */
		public function AbstractUnit(template:AbstractUnitTemplate){
			_template=template;
		}
		
		public function reset():void{
			_template=null;
			FunctionBinder.clearBindingFuns(setTemplate,setWorld_x,setWorld_y,setIsPassable,setPassCost);
			
			_world_x=-1;
			_world_y=-1;
			
			_isPassable=false;
			
			_passCost=0;
		}
		
		/**
		 * 拷贝属性
		 * @param obj
		 * 
		 */
		protected function copyProperties(obj:AbstractUnit):void{
			obj._template=_template;
			obj._world_x=_world_x;
			obj._world_y=_world_y;
			obj._isPassable=_isPassable;
			obj._passCost=_passCost;
		}
		
		public function clone():*{
			var obj:AbstractUnit=new AbstractUnit(_template);
			copyProperties(obj);
			
			return obj;
		}
	}
}